<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">

	var baseDevURL = "${ctx}/make/devIndex";
	var baseFncURL = "${ctx}/make/configIndex";
	var baseMntUrl = "${ctx}/monitor/main";
	var baseEditUrl = "${ctx}/appBaseInfo/edit";
	var appDevMgrURL = "",appFncMgrURL="", mntUrl = "", appid = "";

	function rowClickAfter(rowIndex,curAppId, curAppName) {
		appid = curAppId;
		appDevMgrURL = baseDevURL + "?appid=" + curAppId + "&appName="
				+ encodeURI(encodeURI(curAppName));
		mntURL = baseMntUrl + "?appid=" + curAppId + "&appName="
				+ encodeURI(encodeURI(curAppName));		
		appFncMgrURL =  baseFncURL + "?appid=" + curAppId + "&appName="
			+ encodeURI(encodeURI(curAppName));
		var  arrId = document.getElementsByName("check");
		arrId[rowIndex -1 ].checked=true;
	}

	function doCreate(){
		JLUtil.woInCenterEx('${ctx}/appBaseInfo/create');
	}

	function doDelete(){
		if (appid == "") {
			alert("请选择要删除的应用！");
		} else {
			if(JLUtil.doConfirm("请确认是否需要删除应用[" + appid + "]的配置数据?")){
				if(JLUtil.doConfirm("请再次确认是否需要删除应用[" + appid + "]的配置数据,删除配置后应用程序将无法正常运行?")){
					var authPasswd = prompt("请输入管理员密码进行删除：");
					var postParam = 'appid=' + appid + '&' + 'authPasswd=' + authPasswd;
					$.ajax( {
						type : 'post',
						url : '${ctx}/appmgr/deleteProjectConf',
						dataType : "json",
						data : postParam,
						async : false,
						success : function(data) {//返回json结果
							var result = data.model.ec;
							if (result != 0) {
								alert(data.model.em);
							} else {
								alert("删除应用配置成功!");
								try {
									document.location.reload(true);
								} catch (e) {

								}
							}
						}
					});						
				}
			}
		}
	}

	function doEdit(){
		if (appid == "") {
			alert("请选择应用！");
		} else {
			JLUtil.woInCenterEx(baseEditUrl + '?appid=' + appid);
		}
	}

	function doBaseProject(){
		if (appid == "") {
			alert("请选择应用！");
		} else {
			var url = "${ctx}/appmgr/readyBaseProject" + "?appid=" + appid;
			JLUtil.woInCenterEx(url);
		}
	}

	function doCopyProjectConf(){
		if (appid == "") {
			alert("请选择应用！");
		} else {
			var url = "${ctx}/appmgr/readyProjectConf" + "?appid=" + appid;
			JLUtil.woInCenterEx(url);
		}		
	}

	function doAppDevMgr() {
		if (appid == "") {
			alert("请选择应用！");
		} else {
			document.getElementById("linkPage").href = appDevMgrURL;
			document.getElementById('linkPage').click();
		}
	}

	function doAppConfigMgr() {
		if (appid == "") {
			alert("请选择应用！");
		} else {
			document.getElementById("linkPage").href = appFncMgrURL;
			document.getElementById('linkPage').click();
		}
	}	

	function doMonitor() {
		if (appid == "") {
			alert("请选择要监控的应用！");
		} else {
			document.getElementById("linkPage").href = mntURL;
			document.getElementById('linkPage').click();
		}
	}
</script>
</head>
<body>
<form class="form-horizontal" role="form" method="post" action="${pageContext.request.contextPath }/appBaseInfo/queryList">
<div class="panel panel-default">
   <div class="panel-heading">
      <h3 class="panel-title">
          请输入查询条件
      </h3>
   </div>
   <div class="panel-body">
                       <div class="form-group">
                          <label class="col-xs-1 control-label" for="ds_username">应用编号</label>
                          <div class="col-xs-3">
                             <input class="input-sm form-control" id="useId" name="useId" value="${useId}" type="text"/>
                          </div>
                          <label class="col-xs-1 control-label" for="ds_password">应用名称</label>
                          <div class="col-xs-3">
 									<input class="input-sm form-control" name="useName" id="useName" value="${useName}" type="text" />
                          </div>
                          <div class="col-xs-4">
                          	 <button type="submit" class="btn btn-default btn-sm" >查询</button>                          
                          </div>
                       </div>
                
   </div>
</div>

			<div class="op-btn">
				<c:choose>
					<c:when test="${sessionScope.isconfiger=='Y' }">
						<input type="button" class="btn btn-default" value="应用配置管理"  onclick="doAppConfigMgr()"/>
						<input type="button" class="btn btn-default" value="应用运营分析"  onclick="doMonitor()"/>
					</c:when>
					<c:when test="${sessionScope.isdeveloper=='Y' }">
						<input type="button" class="btn btn-default" value="应用开发管理"  onclick="doAppDevMgr()"/>
						<input type="button" class="btn btn-default" value="应用运营分析"  onclick="doMonitor()"/>
					</c:when>
					<c:otherwise>
						<input type="button" class="btn btn-default" value="创建应用"  onclick="doCreate();"/>
						<input type="button" class="btn btn-default" value="删除应用"  onclick="doDelete();"/>  
						<input type="button" class="btn btn-default" value="基本信息修改"  onclick="doEdit()"/>
						<!-- <input type="button" class="btn btn-default" value="生成基础工程"  onclick="doBaseProject()"/> -->				
						<input type="button" class="btn btn-default" value="应用开发管理"  onclick="doAppDevMgr()"/>
						<input type="button" class="btn btn-default" value="应用配置管理"  onclick="doAppConfigMgr()"/>  
						<input type="button" class="btn btn-default" value="复制应用配置"  onclick="doCopyProjectConf()"/>
						<input type="button" class="btn btn-default" value="应用运营分析"  onclick="doMonitor()"/>
					</c:otherwise>
				</c:choose>
				<a id="linkPage"  target="_blank"/></a>
			</div>		
			<table class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center" class="active">
					    <td>选择</td>
						<td>应用编号</td>
						<td>应用名称</td>
						<td>应用类型</td>
						<td>应用工程状态</td>
						<td>应用工程日期</td>
						<td>应用工程地址</td>
						<td>当前版本</td>
						<td>版本发布日期</td>						
					</tr>
				</thead>				
				<tbody>
				<c:forEach items="${AppModuleUseList}" var="AppModuleUse" varStatus="s" >
					<tr align="center">
						<td><input type="radio" name="check" id="check" value="15"></input></td>
						<td>${AppModuleUse.appId}</td>
						<td>${AppModuleUse.appName}</td>
						<td><c:choose>
							<c:when test="${AppModuleUse.appType eq '10'}">    
		                                   	手机
		                                </c:when>
							<c:when test="${AppModuleUse.appType eq '20'}">    
		                                   	平板
		                                </c:when>
							</c:choose>
						</td>
						<td><c:choose>
							<c:when test="${AppModuleUse.appProjectState==0}">    
		                                   	未初始化工程
		                                </c:when>
							<c:when test="${AppModuleUse.appProjectState==1}">    
		                                   	已创建基础工程
		                                </c:when>
							<c:otherwise> 
		                                	已生成模块代码
		                              </c:otherwise>
						</c:choose></td>
						<td>${AppModuleUse.appProjectDate}</td>
						<td>${AppModuleUse.appProjectUrl}</td>
						<td>${AppModuleUse.appVersionId}</td>
						<td>${AppModuleUse.appVersionDate}</td>
					</tr>
				</c:forEach>																					
				</tbody>
			</table>
			<%@ include file="/page/page.jsp" %>
			</form>
	<script language="javascript">
	var preRow = null;
	$('tbody tr').bind(
			'click',
			function() {

				var rowIndex = $(this).prevAll().length + 1;
				if (rowIndex < 1)
					return;

				if (preRow != null) {
					preRow.removeClass("active");
				}
				$(this).addClass("active");
				preRow = $(this);

				// 行单击后事件(传入行号，应用ID,应用名称信息)
				rowClickAfter(rowIndex, $(this).find("td").eq(1).text(),
						$(this).find("td").eq(2).text());
			});
</script>
</body>
</html>
